<template>
  <view class="container">
    <view class="overlay">
      <view class="content">
        <view>
          <image class="logo" src="/static/logo/logo.png"/>
        </view>
        <view>
          <text class="title">庆祝我们的纪念日!</text>
        </view>

        <view>
          <!-- 提示窗示例 -->
          <uni-popup ref="alertDialog" type="dialog">
            <uni-popup-dialog :type="msgType" cancelText="拒绝" confirmText="允许"
                              content="Memorials 申请获得你的微信头像、昵称等信息，以便为你提供更好的服务。"
                              title="微信授权"
                              @confirm="doLogin"
            >

            </uni-popup-dialog>
          </uni-popup>
        </view>

        <view class="q-my-lg">
          <button class="login-button" @click="dialogToggle">登录</button>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import {handleUserLoginAndInfo} from '@/assets/utils/wxlogin';
import {useCommonStore} from '@/stores/commonStore';
import UniPopup from '@dcloudio/uni-ui/lib/uni-popup/uni-popup.vue';
import UniPopupDialog from '@dcloudio/uni-ui/lib/uni-popup-dialog/uni-popup-dialog.vue';

export default {
  components: {
    UniPopup,
    UniPopupDialog
  },
  data() {
    return {
      msgType: 'info',
      commonStore: useCommonStore(),
    }

  },
  methods: {
    dialogToggle() {
      console.log(this.$refs.alertDialog)
      this.$refs.alertDialog && this.$refs.alertDialog.open()
    },
    async doLogin() {
      try {
        await handleUserLoginAndInfo();
      } catch (error) {
        console.log('登录或获取用户信息失败:', error);
        // 提示用户登录失败
        await uni.showToast({
          title: '登录失败，请重试',
          icon: 'none'
        });
      }
    }
  }
}


</script>

<style>
/* 在这里添加你的样式，如果已经定义，可以忽略此部分 */
.container {
  position: relative;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.content {
  text-align: center;
  color: #fff;
}

.title {
  font-size: 48rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.login-button {
  width: 300rpx;
  height: 60rpx;
  background-color: #f8b400; /* 金色 */
  color: #fff;
  border: none;
  border-radius: 30rpx;
  font-size: 24rpx;
  cursor: pointer;
  transition: background-color 0.3s, transform 0.3s;
}

.logo {
  height: 200rpx;
  width: 200rpx;
  margin-top: 200rpx;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 50rpx;
}

.login-button:hover {
  background-color: #e0a300;
  transform: scale(1.05);
}

.login-button:active {
  background-color: #c68c00;
}
</style>
